package com.qk.controller;


import com.qk.anno.Log;
import com.qk.entity.Role;
import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.service.RoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/*private Integer id; // 角色id，主键
    private String name; // 角色名称
    private String label; // 角色标识
    private String remark; // 备注
    private LocalDateTime createTime; // 创建时间
    private LocalDateTime updateTime; // 修改时间*/
@Slf4j
@RequestMapping("/roles")
@RestController
public class RoleController {
    @Autowired
    private RoleService roleService;


    @GetMapping
    public Result list(String name, String label, @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer pageSize) {
        log.info("列表查询{} {} {} {}", name, label, page, pageSize);

        PageResult<Role> list = roleService.roleAllList(name, label, page, pageSize);
        return Result.success(list);
    }
    @Log   //必须设置路径请求参数pathVariable
    @DeleteMapping("/{id}")
    public Result delete( @PathVariable  Integer id) {
        log.info("删除角色{}", id);
        roleService.deleteById(id);
        return Result.success();
    }
    @Log
    @PostMapping
    public Result add(@RequestBody Role role) {
        log.info("新增角色{}", role);
        roleService.addRole(role);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result selectRoleById(@PathVariable
                                 Integer id) {
        log.info("查询角色{}", id);
        Role roleList = roleService.selectRoleById(id);
        return Result.success(roleList);
    }
    @Log
    @PutMapping
    public Result update(@RequestBody Role role) {
        log.info("更新角色{}", role);
        roleService.updateRole(role);
        return Result.success();
    }
    //查询所有角色
    @GetMapping("/list")
    public Result selectAllRole() {
        log.info("查询所有角色");
        List<Role> roleList = roleService.selectAllRole();
        return Result.success(roleList);
    }
}
